Page({
  /**
   * 页面的初始数据
   */
  data: {
    needPayAmount: "",
    paymentList: [],
    paystatus: false,
    goodsPrice: "",
    container: '',
    content: {
    },
    tablistarray: {},
    payList: {
    },
    deliveryCharge: '',
    goodsQuantity: '',
    orderAmount: '',
    inTradeNo: '',
    otherCharge: '',
    goodsName: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.content = options;
    this.setData({
      content: options,
      inTradeNo: options.inTradeNo,
      goodsName: options.goodsName
    })
    this.getPayList();
  },
  closebtn () {
    wx.navigateBack(-1);
  },
  getPayList () {     //缴费确认列表信息
    const request = {
      inTradeNo: this.data.inTradeNo
    }
    wx.$API['workService/orderList'](request).then((response) => {
      this.setData({
        paymentList: response.data[0].orderGoodsList,
        needPayAmount: response.data[0].needPayAmount,
        deliveryCharge: response.data[0].deliveryCharge,
        otherCharge: response.data[0].otherCharge,
      })
    }).catch((error) => {
      wx.showToast({
        title: error,
        icon: "none"
      })
    })
  },
  confirm () {
    const request = {
      outTradeNo: this.data.inTradeNo,  //订单号
      body: this.data.goodsName    //订单名称
    }
    wx.$API['workService/orderpay'](request).then((response) => {
      this.setData({
        payList: response.data[0]
      })
      this.getPayment();
    }).catch((error) => {
      wx.showToast({
        title: error,
        icon: "none"
      })
    })
  },
  /**
   * @see 调用微信支付接口
   */
  getPayment () {
    wx.requestPayment({
      timeStamp: this.data.payList.timeStamp,
      nonceStr: this.data.payList.nonceStr,
      package: this.data.payList.package,
      signType: this.data.payList.signType,
      paySign: this.data.payList.paySign,
      success: (res) => {
        this.setData({
          paystatus: true
        })
      },
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.success = this.selectComponent("#success");
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (this.data.paystatus == true) {
      var stus = 1;
      setTimeout(() => {
        wx.reLaunch({
          url: '../../workService/paysuccess/index?inTradeNo=' + this.data.inTradeNo + '&stus=' + stus,
        })
      }, 1000)
    }
  },
})